{# SPDX-License-Identifier: Apache-2.0 -#}
{% extends "manage_project_base.html" %}
{% set active_tab = "releases" %}
{% block title %}
  {% trans project_name=project.name, version=release.version %}Manage '{{ project_name }}' – release version {{ version }}{% endtrans %}
{% endblock %}
{% block breadcrumb %}
  <li class="breadcrumbs__breadcrumb">
    <a href="{{ request.route_path('manage.project.releases', project_name=project.normalized_name) }}">
      <i class="fa fa-cubes" aria-hidden="true"></i>
      {{ project.name }}
    </a>
  </li>
  <li class="breadcrumbs__breadcrumb">{% trans version=release.version %}Version {{ version }}{% endtrans %}</li>
{% endblock %}
{% block main %}
  <div class="heading-wsubtitle heading-wsubtitle--in-content">
    <h2 class="heading-wsubtitle__heading">
      {% if not release.yanked %}
        {% set releases = project.active_releases %}
        <a href="{{ request.route_path('manage.project.releases', project_name=project.normalized_name) }}">{% trans %}Releases{% endtrans %}</a>
        <span class="badge badge--neutral">{{ releases|length }}</span>
      {% else %}
        {% set yanked_releases = project.yanked_releases %}
        <a href="{{ request.route_path('manage.project.releases', project_name=project.normalized_name) }}">{% trans %}Yanked releases{% endtrans %}</a>
        <span class="badge badge--neutral">{{ yanked_releases|length }}</span>
      {% endif %}
    </h2>
    <h3 class="heading-wsubtitle__subtitle">
      <strong>{% trans version=release.version %}Version {{ version }}{% endtrans %}</strong> —
      <a href="{{ request.route_path('packaging.release', name=release.project.name, version=release.version) }}">{% trans %}view release{% endtrans %}</a>
    </h3>
  </div>
  {% if files %}
    <table class="table table--files">
      <caption class="sr-only">{% trans version=release.version, project_name=project.name %}Files for release {{ version }} of {{ project_name }}{% endtrans %}</caption>
      <thead>
        <tr>
          <th scope="col">{% trans %}Filename, size{% endtrans %}</th>
          <th scope="col">{% trans %}Type{% endtrans %}</th>
          <th scope="col">{% trans %}Python version{% endtrans %}</th>
          <th scope="col">{% trans %}Upload date{% endtrans %}</th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        {% for file in files %}
          <tr>
            <th scope="row">
              <span class="table__mobile-label">{% trans %}Filename, size{% endtrans %}</span>
              <a href="{{ request.route_url('packaging.file', path=file.path) }}">{{ file.filename }}</a>
              {% if file.size %}({{ file.size|filesizeformat() }}){% endif %}
              <br>
            </th>
            <td>
              <span class="table__mobile-label">{% trans %}Type{% endtrans %}</span>
              {{ file.packagetype|format_package_type }}
            </td>
            <td>
              <span class="table__mobile-label">{% trans %}Python version{% endtrans %}</span>
              {{ file.python_version if file.python_version != 'source' else gettext("None") }}
            </td>
            <td>
              <span class="table__mobile-label">{% trans %}Upload date{% endtrans %}</span>
              {{ humanize(file.upload_time) }}
            </td>
            <td class="table__align-right">
              <nav class="dropdown dropdown--with-icons">
                <button type="button"
                        class="button button--primary dropdown__trigger"
                        aria-haspopup="true"
                        aria-expanded="false"
                        aria-label="{% trans %}View file options{% endtrans %}">
                  {% trans %}Options{% endtrans %}
                  <span class="dropdown__trigger-caret">
                    <i class="fa fa-caret-down" aria-hidden="true"></i>
                  </span>
                </button>
                <ul class="dropdown__content"
                    aria-hidden="true"
                    aria-label="{% trans %}File options{% endtrans %}">
                  <li>
                    <a href="{{ request.route_url('packaging.file', path=file.path) }}"
                       class="dropdown__link">
                      <i class="fa fa-download" aria-hidden="true"></i>
                      {% trans %}Download{% endtrans %}
                    </a>
                  </li>
                  <li>
                    {% set title = gettext("Delete file from") %}
                    {% set confirm_name = "delete_file_from" %}
                    {% set confirm_button_label = gettext("Delete file") %}
                    {% set slug = confirm_name.lower().replace(' ', '-') + '-modal-{}'.format(loop.index) %}
                    <a href="#{{ slug }}" class="dropdown__link">
                      <i class="fa fa-trash-alt" aria-hidden="true"></i>
                      {% trans %}Delete{% endtrans %}
                    </a>
                    {% set extra_fields %}
                      <input name="file_id" type="hidden" value="{{ file.id }}">
                    {% endset %}
                    {% set extra_description %}
                      <p>
                        <strong>{% trans %}Filename:{% endtrans %}</strong> {{ file.filename }}
                      </p>
                      <ul class="no-bullets no-left-margin">
                        <li class="margin-bottom">
                          <input class="inline-checkbox"
                                 type="checkbox"
                                 data-action="input->confirm#check"
                                 data-confirm-target="checkbox">
                          {% trans %}I understand that my users will no longer be able to install this file for this release of this project.{% endtrans %}
                        </li>
                        <li class="margin-bottom">
                          <input class="inline-checkbox"
                                 type="checkbox"
                                 data-action="input->confirm#check"
                                 data-confirm-target="checkbox">
                          {% trans filename=file.filename, href="https://pypi.org/help/#file-name-reuse" %}I understand that I will <a href={{ href }} target="_blank" rel="noopener">not be able to re-upload a file using the same file name</a> {{ filename }}.{% endtrans %}
                        </li>
                        <li class="margin-bottom">
                          <input class="inline-checkbox"
                                 type="checkbox"
                                 data-action="input->confirm#check"
                                 data-confirm-target="checkbox">
                          {% trans %}I understand that I will not be able to undo this.{% endtrans %}
                        </li>
                        <li>
                          <input class="inline-checkbox"
                                 type="checkbox"
                                 data-action="input->confirm#check"
                                 data-confirm-target="checkbox">
                          {% trans %}I understand that the PyPI administrators will not be able to undo this.{% endtrans %}
                        </li>
                      </ul>
                    {% endset %}
                  </li>
                </ul>
              </nav>
              {{ confirm_modal(title, gettext("Project name") , "project_name", project.name, slug, confirm_button_label=confirm_button_label, extra_fields=extra_fields, extra_description=extra_description) }}
            </td>
          </tr>
        {% endfor %}
      </tbody>
    </table>
  {% endif %}
  <div class="callout-block"
       data-controller="dismissable"
       data-dismissable-identifier="uploading">
    {% if files %}
      <h3>{% trans %}Uploading new files{% endtrans %}</h3>
    {% else %}
      <h3>{% trans %}No files found{% endtrans %}</h3>
    {% endif %}
    <button type="button"
            title="{% trans %}Dismiss{% endtrans %}"
            data-action="click->dismissable#dismiss"
            class="callout-block__dismiss"
            aria-label="{% trans %}Close{% endtrans %}">
      <i class="fa fa-times" aria-hidden="true"></i>
    </button>
    <p>
      {% trans href='https://packaging.python.org/guides/distributing-packages-using-setuptools/#uploading-your-project-to-pypi', title=gettext('External link') %}Learn how to upload files on the <a href="{{ href }}" title="{{ title }}" target="_blank" rel="noopener">Python Packaging User Guide</a>{% endtrans %}
    </p>
  </div>
  <h3>{% trans %}Release settings{% endtrans %}</h3>
  {% if not release.yanked %}
    <div class="callout-block callout-block">
      <h3>{% trans %}Yank release{% endtrans %}</h3>
      <p>
        {% if files %}
          {% trans count=files|length %}
          Yanking will mark this release (and {{ count }} file within it) to be ignored when installing in most common scenarios.
        {% pluralize %}
          Yanking will mark this release (and {{ count }} files within it) to be ignored when installing in most common scenarios.
        {% endtrans %}
      {% else %}
        {% trans %}
        Yanking will mark this release to be ignored when installing in most common scenarios.
      {% endtrans %}
    {% endif %}
    {% trans project_name=project.name, version=release.version %}
    This release will still be installable for users pinning to this exact version, e.g. when using <code>{{ project_name }}=={{ version }}</code>.
  {% endtrans %}
  {% trans href="https://www.python.org/dev/peps/pep-0592/" %}
  For more information, see <a href="{{ href }}">PEP 592</a>.
{% endtrans %}
</p>
{% set extra_description %}
  <p>
    {% trans project_name=project.name, version=release.version %}
    You may provide a reason for yanking this release, which will be displayed by pip to users who install <code>{{ project_name }}=={{ version }}</code>.
  {% endtrans %}
</p>
<label for="yanked_reason">{% trans %}Reason (optional){% endtrans %}</label>
<input name="yanked_reason"
       id="yanked_reason"
       type="text"
       autocomplete="off"
       autocapitalize="off"
       spellcheck="false">
{% endset %}
{{ confirm_button(gettext("Yank release") , gettext("Version"), "yank_version", release.version, modifier="--primary", warning=False, extra_description=extra_description) }}
</div>
{% endif %}
<div class="callout-block callout-block--danger"
     data-controller="delete-confirm">
  <h3>{% trans %}Delete release{% endtrans %}</h3>
  <p>
    <i class="fa fa-exclamation-triangle" aria-hidden="true"><span class="sr-only">{% trans %}Warning{% endtrans %}</span></i>
    {% if files %}
      {% trans count=files|length %}
      Deleting will irreversibly delete this release along with {{ count }} file.
    {% pluralize %}
      Deleting will irreversibly delete this release along with {{ count }} files.
    {% endtrans %}
  {% else %}
    {% trans %}Deleting will irreversibly delete this release.{% endtrans %}
  {% endif %}
  <p>
    {% trans %}You will not be able to re-upload a new distribution of the same type with the same version number.{% endtrans %}
  </p>
  <p>
    {% trans %}Deletion will break any downstream projects relying on a pinned version of this package. It is intended as a last resort to address legal issues or remove harmful releases.{% endtrans %}
  </p>
  <p>
    {% trans yank_href=request.user_docs_url('/project-management/yanking'), post_href='https://www.python.org/dev/peps/pep-0440/#post-releases', title=gettext('External link') %}Consider <a href="{{ yank_href }}"
    title="{{ title }}"
    target="_blank"
    rel="noopener">yanking</a> this release, making a new release or a <a href="{{ post_href }}"
    title="{{ title }}"
    target="_blank"
    rel="noopener">post release</a> instead.{% endtrans %}
  </p>
  <ul class="no-bullets">
    <li>
      <input type="checkbox"
             data-action="input->delete-confirm#check"
             data-delete-confirm-target="input">
      {% trans release_version=release.version %}I understand that I am permanently deleting all files for the {{ release_version }} release of this project.{% endtrans %}
    </li>
    <li>
      <input type="checkbox"
             data-action="input->delete-confirm#check"
             data-delete-confirm-target="input">
      {% trans %}I understand that my users will no longer be able to install this release of this project.{% endtrans %}
    </li>
    <li>
      <input type="checkbox"
             data-action="input->delete-confirm#check"
             data-delete-confirm-target="input">
      {% trans href="https://pypi.org/help/#file-name-reuse" %}I understand that I will <a href="{{ href }}" target="_blank" rel="noopener">not be able to re-upload any deleted files using the same file names</a>.{% endtrans %}
    </li>
    <li>
      <input type="checkbox"
             data-action="input->delete-confirm#check"
             data-delete-confirm-target="input">
      {% trans %}I understand that I will not be able to undo this.{% endtrans %}
    </li>
    <li>
      <input type="checkbox"
             data-action="input->delete-confirm#check"
             data-delete-confirm-target="input">
      {% trans %}I understand that the PyPI administrators will not be able to undo this.{% endtrans %}
    </li>
  </ul>
</p>
{{ confirm_button(gettext("Delete release") , gettext("Version"), "delete_version", release.version, additional_attributes="data-delete-confirm-target=button") }}
</div>
{% endblock %}
